package com.yuange.promethues.utils.common;

import com.alibaba.fastjson.JSONObject;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;

/**
 * @作者：工号308、袁智彪
 * @时间：2023/1/6 15:04
 */
public class TelnetUtil {

    public static boolean telnet(String hostname, int port){
        Socket socket = new Socket();
        boolean isConnected = false;
        try {
            socket.connect(new InetSocketAddress(hostname, port), 200); // 建立连接
            isConnected = socket.isConnected(); // 通过现有方法查看连通状态
        } catch (Exception e) {
//            System.out.println("false"); // 当连不通时，直接抛异常，异常捕获即可
        }finally{
            try {
                socket.close(); // 关闭连接
            } catch (Exception e) {
//                System.out.println("false");
            }
        }
        return isConnected;
    }

}
